package baseFx.tests.database.monitor;

import baseFx.common.Assert;
import baseFx.common.utils.ClassUtils;
import baseFx.database.monitor.After;
import baseFx.database.monitor.Before;
import baseFx.database.monitor.DbWatcher;
import baseFx.database.monitor.WatchOperation;
import baseFx.database.where.ExecuteWhere;

import java.lang.reflect.Field;

@DbWatcher
class WatcherAll {
    @Before(WatchOperation.insert)
    public void before(Class table, Object model) {
        Assert.isEquals(table, Member2.class);
        Field id = ClassUtils.field(table, "id");
        Assert.isNotNull(id);
        Assert.isEquals(ClassUtils.getValue(id, model), 333);
    }

    @After(WatchOperation.update)
    public void after(Class table, Object model, ExecuteWhere where) {
        Assert.isEquals(table, Member.class);
        Field id = ClassUtils.field(table, "id");
        Field name = ClassUtils.field(table, "name");
        Assert.isNotNull(id);
        Assert.isNotNull(name);
        Assert.isEquals(ClassUtils.getValue(name, model), "aaa");
        Assert.isEquals(ClassUtils.getValue(id, where.eq()), 111);
    }
}
